<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no" />
    <title>首页</title>
    <link rel="stylesheet" type="text/css" href="../c/aui.css" />
    <style>
        .f {
            position: fixed;
            bottom: 0;
            left: 0;
            width: 100%;
            color: #fff;
            padding: 0 0.75rem;
            font-size: 0.75rem;
            background: #020202
        }

        .f div:last-child {
            color: #FF2C55;
        }
        .f img{
          width: 1.2rem;
        }
    </style>
</head>

<body>
    <div class="f aui-card-list-footer" id="sx-footer">
        <div tapmode onclick="_close()">取消</div>
        <div tapmode onclick="reset();"><img src="../i/reset.png" /></div>
        <div tapmode onclick="save()">确认</div>
    </div>
</body>
<script type="text/javascript" src="../j/api.js"></script>
<script type="text/javascript">
    var FNImageClip
    apiready = function() {
      api.parseTapmode();
      FNImageClip = api.require('FNImageClip');
      allowEdit();
    }
        // 裁剪头像
    function allowEdit() {
        $api.fixTabBar($api.byId('sx-footer'))
        var f = $api.offset($api.byId('sx-footer')).h;
        FNImageClip.open({
            rect: {
                x: 0,
                y: 0,
                w: api.winWidth,
                h: api.winHeight - f
            },
            srcPath: api.pageParam['img'],
            isMinWidth: false,
            isMinHeight: false,
            isHideGrid: true,
            style: {
                mask: 'rgba(0, 0, 0, 0.7)',
                clip: {
                  w: api.winWidth,
                  h: api.winWidth,
                    x: 0,
                    y: ((api.winHeight / 2) / 2) - (f/2) ,
                    borderColor: '#f00',
                    borderWidth: 1,
                    appearance: 'rectangle'

                }
            },
            fixedOn: api.frameName
        }, function(ret, err) {
            if (ret) {
                console.log(JSON.stringify(ret));
            } else {
                console.log(JSON.stringify(err));
            }
        });
    }
    function save(){
      FNImageClip.save({
          destPath: 'fs://www_suxiangw_com/qq1424445608.png',
          copyToAlbum: false,
          quality: 1
      }, function(ret, err) {
          if (ret) {
              console.log(JSON.stringify(ret));
              if(ret.destPath){
                _loading();
                _qiniu(ret.destPath,function(ret,err){
                  if (ret.status) {
            				console.log(JSON.stringify(ret));
            					if (ret.oper == "complete") {
            							//上传成功后组装访问路径，或直接访问文档
            					  var img = ret.info.key;
                        console.log(JSON.stringify(api.pageParam))
                        _ajax('member/img',function(ret,err){
                          if (ret) {
                  					_msg(ret.ret ? ret.ret : ret.err);
                  					if (ret.ret) {
                              api.closeWin({
                                  name: 'img'
                              });
                              api.execScript({
            									    name: 'member_sz',
            									    frameName: 'member_sz',
            									    script: 'img_name("'+img+'")'
            									});
                  						_zhen();
                              _close();
                  					}
                  				} else {
                  					_alert(JSON.stringify(err))
                  				}
                          _loadingCloes();
                          _heibai();
                        },{img:img,datu:api.pageParam['datu']})
            					} else if (ret.oper == "progress") {
            							//上传过程中获取进度数据
            					}
            			}else{
                    _loadingCloes();
            				console.log(JSON.stringify(err));
            			}

                });
              }
          } else {
            _loadingCloes();
              console.log(JSON.stringify(err));
          }
      });
    }
    function reset(){
      FNImageClip.reset();
    }

</script>

</html>
